home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -in_the_mag- / emulation / consoles / amigavgb / amigavgb.c < prev    next >
C/C++ Source or Header  |  1997-12-12  |  6KB  |  253 lines

  1. /** VGB: portable GameBoy emulator ***************************/
  2. /**                                                         **/
  3. /**                        AmigaVGB.c                       **/
  4. /**                                                         **/
  5. /** This file contains Amiga main() procedure starting      **/
  6. /** the emulation.                                          **/
  7. /**                                                         **/
  8. /** Copyright (C) Lars Malmborg 1996                        **/
  9. /** based on a version by Marat Fayzullin 1995              **/
  10. /**     You are not allowed to distribute this software     **/
  11. /**     commercially. Please, notify me, if you make any    **/
  12. /**     changes to this file.                               **/
  13. /*************************************************************/
  14.  
  15. /** Yo! Amiga coder! *****************************************/
  16. /**                                                         **/
  17. /**    You can compile with or without GameBoy debugging.   **/
  18. /** To turn it on, define DEBUG. There is also another flag **/
  19. /** you can set, if you want to generate a version that     **/
  20. /** uses CyberGraphX directlly. I didn't notice any speed   **/
  21. /** improvement, but you might if you are using another     **/
  22. /** graphics card than I do (PicassoII). Define CYBER to    **/
  23. /** enable this.                                            **/
  24. /**    The port is made quite clean, so you can take the    **/
  25. /** Unix distribution and copy smakefile, SCOPTIONS and the **/
  26. /** Amiga#? into it without collision, and type smake.      **/
  27. /**                                                         **/
  28. /*************************************************************/
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <signal.h>
  34.  
  35.  
  36. /* Amiga includes */
  37. #include <proto/exec.h>
  38. #include <proto/dos.h>
  39. #include <proto/intuition.h>
  40. #include <proto/graphics.h>
  41. #include <proto/asl.h>
  42. #include <dos/rdargs.h>
  43. #include <exec/memory.h>
  44. //#include <devices/audio.h>
  45.  
  46. #include "GB.h"
  47. #include "AmigaHelp.h"
  48.  
  49.  
  50. extern char *Title;
  51.  
  52. extern word Trap;
  53. BPTR lock;
  54.  
  55. extern BOOL ScaleUp;
  56. extern STRPTR PubScreen;
  57.  
  58. void SetColors(int,char*);
  59.  
  60. /****************************************************************/
  61. /*** Amiga specific functions and defines                     ***/
  62. /************************************** TO BE WRITTEN BY USER ***/
  63. STRPTR ReqFile(void);
  64.  
  65. #define OPT_CARTRIDGE ((STRPTR)(ArgPtrs[0]))
  66. #define OPT_VERBOSE ((ULONG*)(ArgPtrs[1]))
  67. #define OPT_VPERIOD ((ULONG*)(ArgPtrs[2]))
  68. #define OPT_UPERIOD ((ULONG*)(ArgPtrs[3]))
  69. #define OPT_HELP ((BOOL)(ArgPtrs[4]))
  70. #define OPT_CHEAT ((STRPTR)(ArgPtrs[5]))
  71.  
  72. #define OPT_DELAY ((BOOL)(ArgPtrs[6]))
  73. #define OPT_NOCRC ((BOOL)(ArgPtrs[7]))
  74. #define OPT_AUTOA ((BOOL)(ArgPtrs[8]))
  75. #define OPT_AUTOB ((BOOL)(ArgPtrs[9]))
  76.  
  77. #define OPT_TRAP ((STRPTR)(ArgPtrs[10]))
  78. #define OPT_COLORS ((STRPTR)(ArgPtrs[11]))
  79. #define OPT_BCOLORS ((STRPTR)(ArgPtrs[12]))
  80. #define OPT_SCOLORS ((STRPTR)(ArgPtrs[13]))
  81. #define OPT_WCOLORS ((STRPTR)(ArgPtrs[14]))
  82. #define OPT_SCALEUP ((BOOL)(ArgPtrs[15]))
  83. #define OPT_PSCREEN ((STRPTR)(ArgPtrs[16]))
  84.  
  85. main(void)
  86. {
  87.     LONG ArgPtrs[17]={0};
  88.     struct RDArgs *Args;
  89.     STRPTR filename_buf=NULL;
  90.  
  91.   TrapBadOps=1;LineDelay=0;CheckCRC=1; 
  92.   VPeriod=69905;UPeriod=2;IntSync=1;
  93.   Verbose=5;SndName=NULL;
  94.     ScaleUp=FALSE;PubScreen=NULL;
  95.  
  96.     if(Args = ReadArgs("CR=Cartridge/K,V=Verbose/K/N,VP=VPeriod/K/N,UP=UPeriod/K/N,Help/S,Cheat/K,Delay/S,NoCRC/S,AutoA/S,AutoB/S,Trap/K,C=Colors/K,BC=BColors/K,SC=SColors/K,WC=WColors/K,2=ScaleUp/S,PS=PublicScreen/K",ArgPtrs,NULL))
  97.     {
  98.         if(OPT_CARTRIDGE)
  99.         {
  100.             if (filename_buf=AllocVec(strlen(OPT_CARTRIDGE)+1,MEMF_ANY|MEMF_CLEAR))
  101.                 strcpy(filename_buf,OPT_CARTRIDGE);
  102.         }
  103.  
  104.         if(OPT_VERBOSE)
  105.         {
  106.             Verbose = (int)(*OPT_VERBOSE);
  107.         };
  108.  
  109.         if(OPT_VPERIOD)
  110.         {
  111.             VPeriod = (int)(*OPT_VPERIOD);
  112.         };
  113.  
  114.         if(OPT_UPERIOD)
  115.         {
  116.             UPeriod = (int)(*OPT_UPERIOD);
  117.         };
  118.  
  119.         if(OPT_HELP)
  120.         {
  121.             puts(HelpText);
  122.             FreeArgs(Args);
  123.             exit(0);
  124.         };
  125.  
  126.         if(OPT_CHEAT)
  127.         {
  128.             if(!AddCheat(OPT_CHEAT))
  129.                 printf("Wrong cheat data supplied\n");
  130.         };
  131.  
  132.         if(OPT_DELAY)
  133.         {
  134.             LineDelay=1;
  135.         };
  136.  
  137.         if(OPT_NOCRC)
  138.         {
  139.             CheckCRC=0;
  140.         };
  141.  
  142.         if(OPT_AUTOA)
  143.         {
  144.             AutoA=1;
  145.         };
  146.  
  147.         if(OPT_AUTOB)
  148.         {
  149.             AutoB=1;
  150.         };
  151.  
  152. #ifdef DEBUG
  153.         if(OPT_TRAP)
  154.         {
  155.             if(!stricmp("now",OPT_TRAP))
  156.             {
  157.                 Trace=1;
  158.             }
  159.             else
  160.             {
  161.                 sscanf(OPT_TRAP,"%hx",&Trap);
  162.             }
  163.         }
  164. #endif
  165.  
  166.         if(OPT_COLORS)
  167.         {
  168.             SetColors(0,OPT_COLORS);
  169.             SetColors(4,OPT_COLORS);
  170.             SetColors(8,OPT_COLORS);
  171.         }
  172.  
  173.         if(OPT_BCOLORS)
  174.         {
  175.             SetColors(0,OPT_BCOLORS);
  176.         }
  177.  
  178.         if(OPT_SCOLORS)
  179.         {
  180.             SetColors(4,OPT_SCOLORS);
  181.         }
  182.  
  183.         if(OPT_WCOLORS)
  184.         {
  185.             SetColors(8,OPT_WCOLORS);
  186.         }
  187.  
  188.         if(OPT_SCALEUP)
  189.         {
  190.             ScaleUp=TRUE;
  191.         };
  192.  
  193.         if(OPT_PSCREEN)
  194.         {
  195.             if (PubScreen=AllocVec(strlen(OPT_PSCREEN)+1,MEMF_ANY|MEMF_CLEAR))
  196.                 strcpy(PubScreen,OPT_PSCREEN);
  197.         }
  198.  
  199.         FreeArgs(Args);
  200.  
  201.         if (!filename_buf)
  202.         {
  203.             if((filename_buf = ReqFile()) == NULL) exit(0);
  204.         }
  205.  
  206.   if(!InitMachine())
  207.     {
  208.       TrashMachine();
  209.         if (filename_buf)
  210.             FreeVec(filename_buf);
  211.         if (PubScreen)
  212.             FreeVec(PubScreen);
  213.         return(1);
  214.     }
  215.     StartGB(filename_buf);
  216.     TrashGB();
  217.   TrashMachine();
  218.     if (filename_buf)
  219.         FreeVec(filename_buf);
  220.     if (PubScreen)
  221.         FreeVec(PubScreen);
  222.   return(0);
  223.     }
  224. }
  225.  
  226. STRPTR ReqFile(void)
  227. {
  228. struct FileRequester *AslReq;
  229. STRPTR file=NULL;
  230. WORD namelen;
  231.  
  232.     if(AslReq = (struct FileRequester*)AllocAslRequestTags(ASL_FileRequest,
  233.             ASLFR_TitleText,"Select a cartridge!",
  234.             ASLFR_PositiveText,"Play",
  235.             ASLFR_NegativeText,"Trash",
  236.             ASLFR_RejectIcons,TRUE,
  237.             TAG_END))
  238.     {
  239.         if(AslRequest(AslReq,NULL))
  240.         {
  241.             namelen = strlen(AslReq->fr_File) + strlen(AslReq->fr_Drawer) + 2;
  242.             if(file = AllocVec(namelen,MEMF_ANY | MEMF_CLEAR))
  243.             {
  244.                 strcpy(file,AslReq->fr_Drawer);
  245.                 AddPart(file,AslReq->fr_File,namelen);
  246.                 printf("Looking for file: '%s'\n",file);
  247.             }
  248.         }
  249.         FreeAslRequest((APTR)AslReq);
  250.     }
  251.     return file;
  252. }
  253.